import sys
import platform
sys.path.append('..')
from run_suite.suite import *
import time

if __name__ == '__main__':
    leader = Engine()
    follower = Engine()
    leader.start('leader.cfg', 'leader')
    time.sleep(1)
    follower.start('follower.cfg', 'follower')
    time.sleep(1)
    follower.stop();
    time.sleep(5)
    follower.start('follower.cfg', 'follower')
    time.sleep(1)
    leader.stop()
    follower.stop()
    if checkLog('follower.log', 'Site joined [1-1-1] <-> [1-2-1]') and checkLog('leader.log', 'Site joined [1-2-1] <-> [1-1-1]', 2):
        writeResult('follower_crash_and_rejoin', 'pass')
    else:
        writeResult('follower_crash_and_rejoin', 'fail', 'Site not joined')